<template>
  <div class="cat-page">
    <template v-for="item in catList" :key="item.id">
      <div style="margin-right: 14px">
        <h1>{{ item.name }}-{{ getCatByCreedsLoading }}</h1>
        <img class="cat-page__cat-img" alt="cat" :src="item.image.url" />
      </div>
    </template>
    <button @click="changeImg">换一批aaaa</button>
  </div>
</template>

<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { CatApi, getCatByCreeds } from '@/api/demo/cat'
import { CatItem } from '@/api/demo/cat/models/index'
import useLoadState from '@/store/loadState'

let page = 1
const loadState = useLoadState()
const catList = ref<CatItem[]>([])
const getCatByCreedsLoading = loadState.isOpLoading(CatApi.GET_CAT_BY_BREEDS)

const changeImg = async () => {
  catList.value = await getCatByCreeds({ page: page++, limit: 6 })
}

onMounted(async () => {
  catList.value = await getCatByCreeds({ page, limit: 6 })
})
</script>

<style lang="scss" scoped>
.cat-page {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  .cat-page__cat-img {
    width: 250px;
    height: 250px;
    object-fit: contain;
  }
}
</style>
